//https://www.nowcoder.com/practice/1718131e719746e9a56fb29c40cc8f95?tpId=230&tqId=39753&ru=/exam/oj

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    vector<int> v(n + 1, 0);
    // 1 <= i <= n
    for (int i = 1; i <= n; ++i)
    {
        cin >> v[i];
    }

    vector<int> dp(100001, INT32_MIN);
    int max_sum = INT32_MIN;
    for (int i = 1; i <= n; ++i)
    {
        dp[i] = max(dp[i - 1] + v[i], v[i]);
        max_sum = max(max_sum, dp[i]);
    }
    cout << max_sum << endl;

    return 0;
}